package com.cn.wanxi.service.impl;

import com.cn.wanxi.dao.NavDao;
import com.cn.wanxi.dao.impl.NavImpl;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.NavService;
import redis.clients.jedis.Jedis;

import java.util.List;

public class NavServiceImpl implements NavService {
    //    @Override
//    public List<NavModel> getNavModelList() {
//        String a = "aaa";
//        int age = 10;
//        NavModel[] navModel = new NavModel[10];
//        for (int i = 0; i < age; i++) {
//
//        }
//        return null;
//    }
    private NavDao navDao = new NavImpl();

    @Override
    public ResultModel add(NavModel navModel) {
//        NavDao navDao = new NavImpl();
        return ResultModel.getResultModel(navDao.add(navModel));
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCode(0);
//        resultModel.setMsg("");
//        resultModel.setData(null);
//        resultModel.setCount(navDao.add(navModel));
//        return resultModel;
    }

    @Override
    public ResultModel deltete(NavModel navModel) {
//        NavDao navDao = new NavImpl();
//        return ResultModel.getResultModel(navDao.delete(navModel));
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCode(0);
//        resultModel.setMsg("");
//        resultModel.setData(null);
//        resultModel.setCount(navDao.delete(navModel));
//        return resultModel;
        int count = navDao.delete(navModel);
        Jedis jedis = new Jedis();

        if (count > 0) {
            jedis.del("navHref", "navTitle");
        }
        return ResultModel.getResultModel(count);
    }

    @Override
    public ResultModel update(NavModel navModel) {
//        NavDao navDao = new NavImpl();
        return ResultModel.getResultModel(navDao.update(navModel));
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCode(0);
//        resultModel.setMsg("");
//        resultModel.setData(null);
//        resultModel.setCount(navDao.update(navModel));
//        return resultModel;
    }

    @Override
    public ResultModel findAll(NavModel navModel) {
//        NavDao navDao = new NavImpl();
        List<NavModel> all = navDao.findAll(navModel);
        int count = navDao.getCount(navModel);
        return ResultModel.getResultModel(count, all);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(count);
//        resultModel.setMsg("");
//        resultModel.setCode(0);
//        resultModel.setData(all);
//        return resultModel;
    }

    @Override
    public ResultModel findById(NavModel navModel) {
//        NavDao navDao = new NavImpl();
        NavModel model = navDao.findById(navModel);
        return ResultModel.getResultModel( model);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(0);
//        resultModel.setMsg("");
//        resultModel.setCode(0);
//        resultModel.setData(model);
//        return resultModel;
    }

    @Override
    public ResultModel getCount(NavModel navModel) {
//        NavDao navDao = new NavImpl();
        int count = navDao.getCount(navModel);
        return ResultModel.getResultModel(count);
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(count);
//        resultModel.setMsg("");
//        resultModel.setCode(0);
//        resultModel.setData(null);
//        return resultModel;
    }

    @Override
    public ResultModel enable(NavModel navModel) {
        return null;
    }


}
